CREATE TABLE account (
  id numeric NOT NULL ,
  username VARCHAR(45) NOT NULL,
  password VARCHAR(100) NOT NULL,
  role VARCHAR(45) NOT NULL,  
  enable SMALLINT NOT NULL ,
  date_create DATE NOT NULL,
  PRIMARY KEY  (id)
  );

CREATE SEQUENCE account_sequence;
/

CREATE OR REPLACE TRIGGER account_before_trigger 
BEFORE INSERT ON account FOR EACH ROW 
BEGIN
  IF (:NEW.id IS NULL) THEN
    SELECT account_sequence.nextval INTO :NEW.id
    FROM DUAL;
  END IF;
END;
/

INSERT INTO account(username,password,role,enable,date_create)
VALUES('admin','-2015','ADMIN','1',TO_DATE('2015-01-01','YYYY-MM-DD'));

CREATE TABLE news (
  id numeric NOT NULL ,
  title VARCHAR(255) NOT NULL,
  intro CLOB DEFAULT NULL,
  thumbnail VARCHAR(100),
  content CLOB DEFAULT NULL,
  category SMALLINT NOT NULL ,
  tags NVARCHAR2(1000),
  enable SMALLINT NOT NULL ,
  last_update DATE NOT NULL,
  PRIMARY KEY  (id)
  );

CREATE SEQUENCE news_sequence;
/

CREATE OR REPLACE TRIGGER news_before_trigger 
BEFORE INSERT ON news FOR EACH ROW 
BEGIN
  IF (:NEW.id IS NULL) THEN
    SELECT news_sequence.nextval INTO :NEW.id
    FROM DUAL;
  END IF;
END;
/

CREATE TABLE tag (
  id numeric NOT NULL ,
  name NVARCHAR2(1000) NOT NULL,  
  enable SMALLINT NOT NULL ,
  last_update DATE NOT NULL,
  PRIMARY KEY  (id)
  );

CREATE SEQUENCE tag_sequence;
/

CREATE OR REPLACE TRIGGER tag_before_trigger 
BEFORE INSERT ON tag FOR EACH ROW 
BEGIN
  IF (:NEW.id IS NULL) THEN
    SELECT tag_sequence.nextval INTO :NEW.id
    FROM DUAL;
  END IF;
END;
/

